package com.idanchuang.component.webflux;

import com.idanchuang.component.base.actuator.DcInfoEndpoint;
import com.idanchuang.component.webflux.config.ComponentConfig;
import com.idanchuang.component.webflux.filter.StandardWebFilter;
import com.idanchuang.sun.client.common.tag.TagCollector;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.WebFilter;

import java.util.Collections;

/**
 * @author yjy
 * @date 2019/10/12 16:57
 **/
@Configuration
public class ComponentWebfluxAutoConfiguration {

    @Bean("webFluxComponentConfig")
    @ConfigurationProperties(prefix = "idanchuang.component.web")
    public ComponentConfig componentConfig() {
        return new ComponentConfig();
    }

    @Bean("componentWebfluxFilter")
    @ConditionalOnMissingBean(name = "componentWebfluxFilter")
    public WebFilter componentWebfluxFilter(ComponentConfig componentConfig) {
        return new StandardWebFilter(componentConfig);
    }

    @Bean
    @ConditionalOnMissingBean(name = "dcComponentBaseTagCollector")
    public TagCollector dcComponentBaseTagCollector() {
        return () -> Collections.singleton(DcInfoEndpoint.getComponentVersion());
    }

}
